﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public DataSet QueryMSSTAMM(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM MSSTAMM WHERE  ROWNUM<2 ";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM MSSTAMM  "
                    + " WHERE MSMANDANT=:MSMANDANT AND MSMAT=:MSMAT AND MSVAR=:MSVAR";
                    or1.Parameters.Add("MSMANDANT", OracleType.NVarChar).Value = dwData["MSMANDANT"].ToString();
                    or1.Parameters.Add("MSMAT", OracleType.NVarChar).Value = dwData["MSMAT"].ToString();
                    or1.Parameters.Add("MSVAR", OracleType.NVarChar).Value = dwData["MSVAR"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT DISTINCT GS.* FROM EKPOS GA RIGHT JOIN MSSTAMM GS ON EKPMANDANT=GSCMANDANT "
                        + "  AND cast_to_varchar2(EKPART)=SUBSTR(MSMAT||'                                         ',0,40) AND utl_raw.cast_to_varchar2(EKPVAR)=MSVAR  "
                        + "  WHERE  EKPSA='PO' AND EKPARTGR=8 AND EKPMANDANT=:EKPMANDANT AND  EKPAUFKRS=:EKPAUFKRS AND EKPAUFLFD=:EKPAUFLFD ";
                    or1.Parameters.Add("EKPMANDANT", OracleType.NVarChar).Value = dwData["EKPMANDANT"].ToString();
                    or1.Parameters.Add("EKPAUFKRS", OracleType.NVarChar).Value = dwData["EKPAUFKRS"].ToString();
                    or1.Parameters.Add("EKPAUFLFD", OracleType.NVarChar).Value = dwData["EKPAUFLFD"].ToString();
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "MSSTAMM";
            Return = Result;
            return Return;
        }
    }
}
